package com.xx;

import javax.swing.*;
import java.awt.*;

public class AlignTopExample extends JFrame {

    public AlignTopExample() {
        JPanel panel = new JPanel();
        panel.setLayout(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();
        c.gridx = 0;
        c.gridy = 0;

        // 添加几个按钮作为示例
        JButton button = new JButton("Button1");
        panel.add(button, c);

        c.gridx = 0;
        c.gridy = 1;
        JButton button2 = new JButton("Button2");
        panel.add(button2, c);

        this.add(panel);
        this.setSize(600, 600);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new AlignTopExample();
            }
        });
    }
}
